import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/hj_page/short_video/short_follow_page.dart';
import 'package:tiktokadult/hj_page/short_video/short_video_find_page.dart';
import 'package:tiktokadult/hj_page/short_video/short_video_main_logic.dart';
import 'package:tiktokadult/hj_page/short_video/short_video_page.dart';
import 'package:tiktokadult/hj_page/short_video/view/short_top_menu.dart';
import 'package:tiktokadult/tools_base/widget/keep_alive_widget.dart';

import '../live/live_main_page.dart';

class ShortVideoMainPage extends StatefulWidget {
  final int index; //
  const ShortVideoMainPage({super.key, this.index = 2});

  @override
  State<StatefulWidget> createState() {
    return _ShortVideoMainPageState();
  }
}

class _ShortVideoMainPageState extends State<ShortVideoMainPage> with TickerProviderStateMixin {
  late ShortVideoMainLogic logic;

  @override
  void initState() {
    super.initState();
    logic = ShortVideoMainLogic(index: widget.index);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: logic,
      builder: (_) {
        return Container(
          color: Colors.black,
          child: SafeArea(
            child: Stack(
              fit: StackFit.expand,
              children: [
                TabBarView(
                  controller: logic.tabController,
                  physics: NeverScrollableScrollPhysics(),
                  children: [
                    Container(
                      padding: EdgeInsets.only(top: kToolbarHeight),
                      child: ShortFollowPage(),
                    ),
                    Container(
                      padding: EdgeInsets.only(top: kToolbarHeight),
                      child: LiveMainPage(),
                    ),
                    ShortVideoPage(
                      type: VideoListType.RECOMMEND,
                      tabIndex: 2,
                      superTabController: logic.tabController,
                    ).keepAlive,
                    Container(
                      padding: EdgeInsets.only(top: kToolbarHeight),
                      child: ShortVideoFindPage(),
                    ),
                  ],
                ),
                Positioned(
                  top: 0,
                  left: 0,
                  right: 0,
                  child: Container(
                    height: kToolbarHeight,
                    child: ShortTopMenu(tabController: logic.tabController),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
